﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;

namespace CharityGamesOnline.Modules.Account
{
    public partial class AccountSetting : ModuleSettingsBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!Null.IsNull(ModuleSettings["ViewMode"]) && !string.IsNullOrEmpty((string)ModuleSettings["ViewMode"]))
                {
                    ddlViewMode.SelectedIndex = ddlViewMode.Items.IndexOf(ddlViewMode.Items.FindByValue((string)ModuleSettings["ViewMode"]));
                }

                if (!Null.IsNull(ModuleSettings["ShowSectionHead"]))
                {
                    cbShowSectionHead.Checked = Boolean.Parse(ModuleSettings["ShowSectionHead"].ToString());
                }

                if (!Null.IsNull(ModuleSettings["ShowModuleName"]))
                {
                    cbShowModuleName.Checked = Boolean.Parse(ModuleSettings["ShowModuleName"].ToString());
                }
            }
        }

        public override void UpdateSettings()
        {
            try
            {
                ModuleController objModules = new ModuleController();

                objModules.UpdateModuleSetting(ModuleId, "ViewMode", ddlViewMode.SelectedValue);
                objModules.UpdateModuleSetting(ModuleId, "ShowSectionHead", cbShowSectionHead.Checked.ToString());
                objModules.UpdateModuleSetting(ModuleId, "ShowModuleName", cbShowModuleName.Checked.ToString());                
            }

            catch (Exception exc)
            {
                //Module failed to load 
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
    }
}